package com.letao.server.config;

import com.letao.server.interceptor.LoginInterceptor;
import com.letao.server.interceptor.RefreshTokenInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 拦截器配置
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // token刷新的拦截器
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate))
                .addPathPatterns("/**");
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/user")
                .addPathPatterns("/user/password")
                .addPathPatterns("/usr/address")
                .addPathPatterns("/upload/userImage")
                .addPathPatterns("/seckill/order/user/{id}")
                .addPathPatterns("/order/status/user")
                .addPathPatterns("/order/return/{orderId}")
                .addPathPatterns("/order/pick/{orderId}")
                .addPathPatterns("/order/pay/{orderId}")
                .addPathPatterns("/order/one")
                .addPathPatterns("/message/user")
                .addPathPatterns("/message/user");

//        registry.addInterceptor(new AdminInterceptor(stringRedisTemplate))
//                .addPathPatterns("/admin/test")
//                .addPathPatterns("/upload/skuImage/{id}")
//                .addPathPatterns("/upload/seckill/{id}")
//                .addPathPatterns("/seckill/admin")
//                .addPathPatterns("/product/comment/admin")
//                .addPathPatterns("/order/admin")
//                .addPathPatterns("/order/detail")
//                .addPathPatterns("/order/admin/{id}")
//                .addPathPatterns("/order/status")
//                .addPathPatterns("/statistics/user")
//                .addPathPatterns("/statistics/product")
//                .addPathPatterns("/statistics/order")
//                .addPathPatterns("/message/admin");
    }
}
